// Keeping the log likelihood of a collection of objects, given a certain
// encoding that shares subtructures of the objects, and uses the chinese 
// table allocation to keep graph pointers.
// Arities use their log as their LL
// All SYMBOLS and SPECIALS are not allocated a cost for existing
// For now Integers are not charged for existence, though we may want to later

#ifndef _GRAPHDL_H_
#define _GRAPHDL_H_

#include "interpret.h"
#include "allocator.h"
#include "nolock.h"
#include "restaurant.h"

extern Thing MODELDL;

// Return in MicroNats
inline uint64 IntegerDL(int64 i) { // this may not be a distribution TODO
  return MLn(2 + abs(i));
}

struct GraphDL {
  GraphDL() { inited_ = false; }
  
  void Init(Table<Thing> * table, Thing dlkey) {
    CHECK(!inited_);
    inited_ = true;
    table_ = table;
    dlkey_ = dlkey;
    log_ = NULL;
    indent_ = 0;
  }

  // Call this
  void Add(Thing o, int64 delta);

  void AddReusable(Thing o, int64 delta);
  void AddDefinition(Thing o, int64 delta);
  
  // In MicroNats
  void AddToDL(int64 delta) { 
    TableIntegerAdd(table_, dlkey_.ID(), delta);
  }
  
  bool IsReusable(Thing o);

  bool inited_;
  ostream *log_;
  uint64 indent_;
  Table<Thing> * table_;
  Thing dlkey_;
};

#endif
